package bdqn.service.impl;

import bdqn.dao.PersonMapper;
import bdqn.pojo.Person;
import bdqn.service.PersonService;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("PersonService")
public class PersonServiceImpl implements PersonService {
    @Resource
    private PersonMapper personMapper;


    @Override
    public List<Person> getLsitInfo() {
        List<Person> info = personMapper.getLsitInfo();
        for (Person ps : info) {
            ps.setGender(gettSex(Integer.parseInt(ps.getGender())));
            ps.setRank(gettRank(Integer.parseInt(ps.getRank())));
        }

        return personMapper.getLsitInfo();
    }

    @Override
    public int add(Person ps) {
        return personMapper.add(ps);
    }

    @Override
    public int dete(Integer id) {
        return personMapper.dete(id);
    }

//判断性别方法
public String gettSex(Integer gender){
    String name ="";
        switch(gender){
            case 1:
                    name="男";
                break;
            case 2:
                name="女";
                break;
        }
    return  name;

}
    public String gettRank(Integer rank){
        String name ="";
        switch(rank){
            case 1:
                name="等级1";
                break;
            case 2:
                name="等级2";
                break;
            case 3:
                name="等级3";
                break;
            case 4:
                name="等级4";
                break;
        }
        return  name;

    }
}
